package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.bean.PotentialInfo;
import com.chuji.crmcj.utils.CommonUtil;
import com.chuji.crmcj.utils.NumberUtils;

import java.util.List;

/**
 * Created by w.pitt on 2016/1/29.
 */
public class PotentialListAdapter extends BaseAdapter {

    List<PotentialInfo.ApiParamObjEntity> potentialInfo;
    private ViewHolder holder;
    private Context mContext;
    private Object list;

    public PotentialListAdapter(Context context, List<PotentialInfo.ApiParamObjEntity> potentialInfo) {
        this.potentialInfo = potentialInfo;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return potentialInfo.isEmpty() ? 0 : potentialInfo.size();
    }

    @Override
    public Object getItem(int i) {
        return potentialInfo.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            holder = new ViewHolder();
            view = view.inflate(mContext, R.layout.item_coustomer_list, null);
            holder.mIv_icon = (ImageView) view.findViewById(R.id.iv_level);
            holder.mTv_name = (TextView) view.findViewById(R.id.tv_name);
            holder.mTv_number = (TextView) view.findViewById(R.id.tv_number);
            holder.mTv_sale_name = (TextView) view.findViewById(R.id.tv_sale_name);
            holder.mTv_want_car = (TextView) view.findViewById(R.id.tv_want_car);
            holder.mTv_least_time = (TextView) view.findViewById(R.id.tv_least_time);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        String level = potentialInfo.get(0).getCustomerLevel();
        holder.mIv_icon.setImageDrawable(CommonUtil.getLevelIcon(level));
        holder.mTv_name.setText(potentialInfo.get(0).getName());
        String tel = potentialInfo.get(0).getTel();
        if (tel.length() == 11) {
            holder.mTv_number.setText(NumberUtils.parsePhoneNumber(tel));
        } else {
            holder.mTv_number.setText(potentialInfo.get(0).getTel());
        }
        holder.mTv_least_time.setText(potentialInfo.get(0).getCreateTime());
        holder.mTv_want_car.setText(potentialInfo.get(0).getCarModel());
        return view;
    }

    public List<PotentialInfo.ApiParamObjEntity> getList() {
        return potentialInfo;
    }

    static class ViewHolder {
        private ImageView mIv_icon;
        private TextView mTv_name;
        private TextView mTv_number;
        private TextView mTv_sale_name;
        private TextView mTv_want_car;
        private TextView mTv_least_time;
    }
}
